#include <bits/stdc++.h>

using namespace std;

const int MAXN = 3010;

#define fi first
#define se second

typedef long long ll;
typedef pair<int,ll> pii;
typedef struct {int v,nxt;}edge;

pii f[MAXN][MAXN],tmp[MAXN];
int a[MAXN],siz[MAXN],h[MAXN],cnt,n,m;
edge e[MAXN<<1];

void link(int x,int y){e[++cnt] = (edge){y,h[x]};h[x] = cnt;}

template <typename tp>
void upd(tp &x,tp y){x = y > x ? y : x;}

void dfs(int x,int p){
	for(int i = 0;i <= m;i++) f[x][i] = pii(0,0);
	f[x][1] = pii(0,a[x]);siz[x] = 1;
	for(int i = h[x];i;i = e[i].nxt){
		int y = e[i].v; if(y == p) continue;
		dfs(y,x);
		for(int j = 1;j <= siz[x] + siz[y];j++) tmp[j] = pii(-1,0);
		for(int j = 1;j <= siz[x];j++){
			for(int k = 1;k <= siz[y];k++){
				upd(tmp[k+j],pii(f[x][j].fi + f[y][k].fi + (f[y][k].se > 0),f[x][j].se));
				upd(tmp[k+j-1],pii(f[x][j].fi + f[y][k].fi,f[x][j].se + f[y][k].se));
			}
		}
		for(int j = 1;j <= siz[x] + siz[y];j++) f[x][j] = tmp[j];
		siz[x] += siz[y];
	}
}

int main (){
	int T,x;scanf("%d",&T);
	while(T--){
		scanf("%d",&n);scanf("%d",&m);
		for(int i = 1;i <= n;i++) scanf("%d",&a[i]);
		for(int i = 1;i <= n;i++) scanf("%d",&x),a[i] = x-a[i];
		cnt = 0;
		memset(h,0,sizeof(h));
		for(int i = 1;i < n;i++){
			int x , y; scanf("%d %d",&x,&y);
			link(x,y);link(y,x);
		}
		dfs(1,0);
		printf("%d\n",f[1][m].fi + (f[1][m].se > 0));
	}
	return 0;
}
